// pages/news/news.js
const App = getApp();
const Api = require('../../utils/api.js')
import regeneratorRuntime from '../../utils/runtime.js';
Page({

  /**
   * 页面的初始数据
   */ 
  data: {
    current: 1,
  },

  tabHandle(e) {
    let that = this
    that.setData({
      current: e.currentTarget.dataset.num
    })
  },
  
  detailHandle(e){
    wx.navigateTo({
      url: '/pages/news_detail/news_detail?id=' + e.currentTarget.id,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let _this = this
    this.getMyWorkers()
  },

  getMyWorkers() {
    return new Promise((resolve) => {
      let _this = this;
      let data = {};
      Api.fetch('news', data)
        .then(res => {
          console.log(res.data);
          if (res.data.code == 1) { 
            _this.setData({
              moment: res.data.data.moment,
              notice: res.data.data.notice,
            }, () => {
              resolve(true)
            })
          }
        })
        .catch(e => {
          console.log(e);
        })
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  async onPullDownRefresh() {
    var that = this;
    let res = await that.getMyWorkers()
    if (res) {
      wx.stopPullDownRefresh()
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})